<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>班级信息</title>
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/login.css">
	  <link rel="stylesheet" href="../../css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
		<div class="layui-row">

			<form class="layui-form" lay-filter="dataForm">

				<div class="layui-form-item">
					<label for="reId" class="layui-form-label">
						编号
					</label>
					<div class="layui-input-inline">
						<input type="text" autocomplete="off" id="reId" name="reId" readonly class="layui-input layui-disabled" >
					</div>

					<label for="reTitle" class="layui-form-label">
						红包标题
					</label>
					<div class="layui-input-inline">
						<input type="text" autocomplete="off" id="reTitle" name="reTitle" readonly class="layui-input layui-disabled" >
					</div>
				</div>

 				<div class="layui-form-item" pane="">
					<label class="layui-form-label">发送给 </label>

					<div class="layui-input-block">
						<input type="checkbox"  name="" lay-skin="primary" id="class_all"  lay-filter="class_all" title="全选" value="(1)-(10)">
					</div>

					<div class="layui-input-block">
							<dl>
								<dt id="dt">

								</dt>
							</dl>
					</div>
				</div>

				<div class="layui-form-item">
					<label for="L_repass" class="layui-form-label"></label>
					<button class="layui-btn" lay-filter="update" lay-submit="">保存</button>
				</div>

			</form>

		</div>
	</div>
</body>
		<script>

			layui.use([ 'table','form', 'layer','layedit', 'laydate' ], function() {
				var rowsData = window.parent.formData;
				$ = layui.jquery;
				var form = layui.form, layer = layui.layer;

				form.on('checkbox(class_all)', function(data){
					var a = data.elem.checked;
					if(a == true){
						$("[name='userId']").prop("checked", true);
						form.render('checkbox');
					}else{
						$("[name='userId']").prop("checked", false);
						form.render('checkbox');
					}
				});

				$.ajax({
					url : "/../user/list",
					type : "POST",
					async:false,
					success : function(data) {
						for(var i = 0; i<data.length;i++) {
							$('#dt').append("<dd><input type='checkbox' name='userId' value='"+data[i].userId+"' lay-skin='primary' title='"+data[i].userNickname+"'></dd>");
						}
					},
				});

				form.on('submit(update)', function(data) {
					var array =[];
					$('input[name="userId"]:checked').each(function(index, domEle){
						array.push($(this).val());
					});
					data.field.userId = array;
					$.ajax({
						type : "POST",
						url : "/../re/redEnvelopeSend",
						data : data.field,
						traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
						success : function(result) {
							if(result){
								layer.alert("发送成功", {
									icon : 6
								}, function() {
									var index = parent.layer.getFrameIndex(window.name);
									parent.layer.close(index);
									parent.location.reload();//刷新父页面更新修改后的表格数据
								});
							}else{
								//发异步，把数据提交给
								layer.alert("发送失败", {
									icon : 5
								});
							}
						}
					});
					return false;
				});


				form.val('dataForm', {
					"reId": rowsData.reId // "name": "value"
					,"reTitle": rowsData.reTitle
				});

			});
        </script>

</html>